/*MyPhotoIndex Free Photo Organizer <www.myphotoindex.com>
  Copyright (C) <2006-2009>  <Asaf Yarkoni asaf@yarkoni.net>

  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.*/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MyPhotoIndex.Controls
{
    public partial class ApplicationAlert : FormTemplate
    {
        private Icon m_icon;
        private MessageBoxButtons m_buttons = MessageBoxButtons.OKCancel;
        private CheckBoxParameters m_checkBoxParameters;
        private static IWin32Window m_defaultOwner;

        private static string m_yesStr;

        public static string YesStr
        {
            get { return ApplicationAlert.m_yesStr; }
            set { ApplicationAlert.m_yesStr = value; }
        }
        private static string m_noStr;

        public static string NoStr
        {
            get { return ApplicationAlert.m_noStr; }
            set { ApplicationAlert.m_noStr = value; }
        }

        public ApplicationAlert()
        {
            InitializeComponent();
            pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
        }

        void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            if (m_icon != null)
            {
                e.Graphics.DrawIcon(m_icon, e.ClipRectangle);
            }
        }

        protected override DialogResult GetDialogResult(bool positive)
        {
            DialogResult result = DialogResult.None;

            if (m_buttons == MessageBoxButtons.OKCancel ||
                m_buttons == MessageBoxButtons.OK)
            {
                result = positive ? DialogResult.OK : DialogResult.Cancel;
            }
            else
                if (m_buttons == MessageBoxButtons.YesNo)
                {
                    result = positive ? DialogResult.Yes : DialogResult.No;
                }

            return result;
        }

        private void SetButtons(MessageBoxButtons buttons)
        {
            if (buttons != MessageBoxButtons.OKCancel &&
                buttons != MessageBoxButtons.YesNo && 
                buttons != MessageBoxButtons.OK)
            {
                throw new NotImplementedException("Only MessageBoxButtons.OKCancel and MessageBoxButtons.YesNo are supported");
            }

            if (buttons == MessageBoxButtons.OK)
            {
                base.CancelButtonVisable = false;
            }
            else
            if (buttons == MessageBoxButtons.YesNo)
            {
                base.OkButtonToolTipText = m_yesStr;
                base.CancelButtonToolTipText = m_noStr;
            }

            m_buttons = buttons;
        }

        private void SetIcon(MessageBoxIcon icon)
        {
            switch (icon)
            {
                case MessageBoxIcon.Asterisk:
                    m_icon = SystemIcons.Asterisk;
                    break;
                case MessageBoxIcon.Error:
                    m_icon = SystemIcons.Error;
                    break;
                case MessageBoxIcon.None:
                    m_icon = SystemIcons.Application;
                    break;
                case MessageBoxIcon.Question:
                    m_icon = Resources.Resources.helpIcon;
                  //  m_icon = SystemIcons.Question;
                    break;
                case MessageBoxIcon.Warning:
                    m_icon = Resources.Resources.warningIcon;
                    //m_icon = SystemIcons.Warning;
                    break;
                default:
                    m_icon = SystemIcons.Application;
                    break;
            }
        }

        private void SetDefaultButton(MessageBoxDefaultButton defaultButton)
        {
            
        }

        private void SetOptions(MessageBoxOptions options)
        {
            throw new NotImplementedException();
        }

        private void SetCheckBox(ref CheckBoxParameters checkBoxParameters)
        {
            m_checkBoxParameters = checkBoxParameters;
            checkBox1.Text = m_checkBoxParameters.Text;
            checkBox1.Checked = m_checkBoxParameters.Value;
            checkBox1.Visible = true;
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (m_checkBoxParameters != null)
            {
                m_checkBoxParameters.Value = checkBox1.Checked;
            }
        }

        public static IWin32Window DefaultOwner
        {
            get { return ApplicationAlert.m_defaultOwner; }
            set { ApplicationAlert.m_defaultOwner = value; }
        }

        // Summary:
        //     Displays a message box with specified text.
        //
        // Parameters:
        //   text:
        //     The text to display in the message box.
        //
        // Returns:
        //     One of the System.Windows.Forms.DialogResult values.
        public static DialogResult Show(String text)
        {
            ApplicationAlert al = new ApplicationAlert();
            al.label1.Text = text;
            return al.ShowDialog();
        }
        //
        // Summary:
        //     Displays a message box in front of the specified object and with the specified
        //     text.
        //
        // Parameters:
        //   Text:
        //     The text to display in the message box.
        //
        //   Owner:
        //     An implementation of System.Windows.Forms.IWin32Window that will own the
        //     modal dialog box.
        //
        // Returns:
        //     One of the System.Windows.Forms.DialogResult values.
        public static DialogResult Show(IWin32Window owner, String text)
        {
            ApplicationAlert al = new ApplicationAlert();
            al.label1.Text = text;
            return al.ShowDialog(owner);
        }
        //
        // Summary:
        //     Displays a message box with specified text and caption.
        //
        // Parameters:
        //   caption:
        //     The text to display in the title bar of the message box.
        //
        //   text:
        //     The text to display in the message box.
        //
        // Returns:
        //     One of the System.Windows.Forms.DialogResult values.
        public static DialogResult Show(String text, String caption)
        {
            ApplicationAlert al = new ApplicationAlert();
            al.label1.Text = text;
            al.Text = caption;
            return al.ShowDialog();
        }
        //
        // Summary:
        //     Displays a message box in front of the specified object and with the specified
        //     text and caption.
        //
        // Parameters:
        //   owner:
        //     An implementation of System.Windows.Forms.IWin32Window that will own the
        //     modal dialog box.
        //
        //   caption:
        //     The text to display in the title bar of the message box.
        //
        //   text:
        //     The text to display in the message box.
        //
        // Returns:
        //     One of the System.Windows.Forms.DialogResult values.
        public static DialogResult Show(IWin32Window owner, String text, String caption)
        {
            ApplicationAlert al = new ApplicationAlert();
            al.label1.Text = text;
            al.Text = caption;
            return al.ShowDialog(owner);
        }
        //
        // Summary:
        //     Displays a message box with specified text, caption, and buttons.
        //
        // Parameters:
        //   caption:
        //     The text to display in the title bar of the message box.
        //
        //   buttons:
        //     One of the System.Windows.Forms.MessageBoxButtons values that specifies which
        //     buttons to display in the message box.
        //
        //   text:
        //     The text to display in the message box.
        //
        // Returns:
        //     One of the System.Windows.Forms.DialogResult values.
        //
        // Exceptions:
        //   System.ComponentModel.InvalidEnumArgumentException:
        //     The buttons parameter specified is not a member of System.Windows.Forms.MessageBoxButtons.
        //
        //   System.InvalidOperationException:
        //     An attempt was made to display the System.Windows.Forms.MessageBox in a process
        //     that is not running in User Interactive mode. This is specified by the System.Windows.Forms.SystemInformation.UserInteractive
        //     property.
        public static DialogResult Show(String text, String caption, MessageBoxButtons buttons)
        {
            ApplicationAlert al = new ApplicationAlert();
            al.label1.Text = text;
            al.Text = caption;

            al.SetButtons(buttons);

            return al.ShowDialog();
        }
        //
        // Summary:
        //     Displays a message box in front of the specified object and with the specified
        //     text, caption, and buttons.
        //
        // Parameters:
        //   Owner:
        //     An implementation of System.Windows.Forms.IWin32Window that will own the
        //     modal dialog box.
        //
        //   buttons:
        //     One of the System.Windows.Forms.MessageBoxButtons values that specifies which
        //     buttons to display in the message box.
        //
        //   Caption:
        //     The text to display in the title bar of the message box.
        //
        //   text:
        //     The text to display in the message box.
        //
        // Returns:
        //     One of the System.Windows.Forms.DialogResult values.
        //
        // Exceptions:
        //   System.InvalidOperationException:
        //     An attempt was made to display the System.Windows.Forms.MessageBox in a process
        //     that is not running in User Interactive mode. This is specified by the System.Windows.Forms.SystemInformation.UserInteractive
        //     property.
        //
        //   System.ComponentModel.InvalidEnumArgumentException:
        //     buttons is not a member of System.Windows.Forms.MessageBoxButtons.
        public static DialogResult Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons)
        {
            ApplicationAlert al = new ApplicationAlert();
            al.label1.Text = text;
            al.Text = caption;

            al.SetButtons(buttons);

            return al.ShowDialog(owner);
        }
        //
        // Summary:
        //     Displays a message box with specified text, caption, buttons, and icon.
        //
        // Parameters:
        //   icon:
        //     One of the System.Windows.Forms.MessageBoxIcon values that specifies which
        //     icon to display in the message box.
        //
        //   caption:
        //     The text to display in the title bar of the message box.
        //
        //   buttons:
        //     One of the System.Windows.Forms.MessageBoxButtons values that specifies which
        //     buttons to display in the message box.
        //
        //   text:
        //     The text to display in the message box.
        //
        // Returns:
        //     One of the System.Windows.Forms.DialogResult values.
        //
        // Exceptions:
        //   System.ComponentModel.InvalidEnumArgumentException:
        //     The buttons parameter specified is not a member of System.Windows.Forms.MessageBoxButtons.-or-
        //     The icon parameter specified is not a member of System.Windows.Forms.MessageBoxIcon.
        //
        //   System.InvalidOperationException:
        //     An attempt was made to display the System.Windows.Forms.MessageBox in a process
        //     that is not running in User Interactive mode. This is specified by the System.Windows.Forms.SystemInformation.UserInteractive
        //     property.
        public static DialogResult Show(String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon)
        {
            ApplicationAlert al = new ApplicationAlert();
            al.label1.Text = text;
            al.Text = caption;

            al.SetButtons(buttons);
            al.SetIcon(icon);

            if (m_defaultOwner == null)
            {
                return al.ShowDialog();
            }
            else
            {
                return al.ShowDialog(m_defaultOwner);
            }
        }
        //
        // Summary:
        //     Displays a message box in front of the specified object and with the specified
        //     text, caption, buttons, and icon.
        //
        // Parameters:
        //   Text:
        //     The text to display in the message box.
        //
        //   Icon:
        //     One of the System.Windows.Forms.MessageBoxIcon values that specifies which
        //     icon to display in the message box.
        //
        //   Owner:
        //     An implementation of System.Windows.Forms.IWin32Window that will own the
        //     modal dialog box.
        //
        //   Buttons:
        //     One of the System.Windows.Forms.MessageBoxButtons values that specifies which
        //     buttons to display in the message box.
        //
        //   Caption:
        //     The text to display in the title bar of the message box.
        //
        // Returns:
        //     One of the System.Windows.Forms.DialogResult values.
        //
        // Exceptions:
        //   System.ComponentModel.InvalidEnumArgumentException:
        //     buttons is not a member of System.Windows.Forms.MessageBoxButtons.-or- icon
        //     is not a member of System.Windows.Forms.MessageBoxIcon.
        //
        //   System.InvalidOperationException:
        //     An attempt was made to display the System.Windows.Forms.MessageBox in a process
        //     that is not running in User Interactive mode. This is specified by the System.Windows.Forms.SystemInformation.UserInteractive
        //     property.
        public static DialogResult Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon)
        {
            ApplicationAlert al = new ApplicationAlert();
            al.label1.Text = text;
            al.Text = caption;

            al.SetButtons(buttons);
            al.SetIcon(icon);

            return al.ShowDialog(owner);
        }
        //
        // Summary:
        //     Displays a message box with the specified text, caption, buttons, icon, and
        //     default button.
        //
        // Parameters:
        //   icon:
        //     One of the System.Windows.Forms.MessageBoxIcon values that specifies which
        //     icon to display in the message box.
        //
        //   caption:
        //     The text to display in the title bar of the message box.
        //
        //   buttons:
        //     One of the System.Windows.Forms.MessageBoxButtons values that specifies which
        //     buttons to display in the message box.
        //
        //   defaultButton:
        //     One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies
        //     the default button for the message box.
        //
        //   text:
        //     The text to display in the message box.
        //
        // Returns:
        //     One of the System.Windows.Forms.DialogResult values.
        //
        // Exceptions:
        //   System.ComponentModel.InvalidEnumArgumentException:
        //     buttons is not a member of System.Windows.Forms.MessageBoxButtons.-or- icon
        //     is not a member of System.Windows.Forms.MessageBoxIcon.-or- defaultButton
        //     is not a member of System.Windows.Forms.MessageBoxDefaultButton.
        //
        //   System.InvalidOperationException:
        //     An attempt was made to display the System.Windows.Forms.MessageBox in a process
        //     that is not running in User Interactive mode. This is specified by the System.Windows.Forms.SystemInformation.UserInteractive
        //     property.
        public static DialogResult Show(String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
        {
            ApplicationAlert al = new ApplicationAlert();
            al.label1.Text = text;
            al.Text = caption;

            al.SetButtons(buttons);
            al.SetIcon(icon);
            al.SetDefaultButton(defaultButton);

            return al.ShowDialog();
        }

        public static DialogResult Show(String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, ref CheckBoxParameters checkBoxParameters)
        {
            ApplicationAlert al = new ApplicationAlert();
            al.label1.Text = text;
            al.Text = caption;

            al.SetButtons(buttons);
            al.SetIcon(icon);
            al.SetDefaultButton(defaultButton);

            al.SetCheckBox(ref checkBoxParameters);

            return al.ShowDialog();
        }

        //
        // Summary:
        //     Displays a message box in front of the specified object and with the specified
        //     text, caption, buttons, icon, and default button.
        //
        // Parameters:
        //   Icon:
        //     One of the System.Windows.Forms.MessageBoxIcon values that specifies which
        //     icon to display in the message box.
        //
        //   Owner:
        //     An implementation of System.Windows.Forms.IWin32Window that will own the
        //     modal dialog box.
        //
        //   defaultButton:
        //     One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies
        //     the default button for the message box.
        //
        //   buttons:
        //     One of the System.Windows.Forms.MessageBoxButtons values that specifies which
        //     buttons to display in the message box.
        //
        //   Caption:
        //     The text to display in the title bar of the message box.
        //
        //   text:
        //     The text to display in the message box.
        //
        // Returns:
        //     One of the System.Windows.Forms.DialogResult values.
        //
        // Exceptions:
        //   System.ComponentModel.InvalidEnumArgumentException:
        //     buttons is not a member of System.Windows.Forms.MessageBoxButtons.-or- icon
        //     is not a member of System.Windows.Forms.MessageBoxIcon.-or- defaultButton
        //     is not a member of System.Windows.Forms.MessageBoxDefaultButton.
        //
        //   System.InvalidOperationException:
        //     An attempt was made to display the System.Windows.Forms.MessageBox in a process
        //     that is not running in User Interactive mode. This is specified by the System.Windows.Forms.SystemInformation.UserInteractive
        //     property.
        public static DialogResult Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
        {
            ApplicationAlert al = new ApplicationAlert();
            al.label1.Text = text;
            al.Text = caption;

            al.SetButtons(buttons);
            al.SetIcon(icon);
            al.SetDefaultButton(defaultButton);

            return al.ShowDialog(owner);
        }
        //
        // Summary:
        //     Displays a message box with the specified text, caption, buttons, icon, default
        //     button, and options.
        //
        // Parameters:
        //   icon:
        //     One of the System.Windows.Forms.MessageBoxIcon values that specifies which
        //     icon to display in the message box.
        //
        //   options:
        //     One of the System.Windows.Forms.MessageBoxOptions values that specifies which
        //     display and association options will be used for the message box. You may
        //     pass in 0 if you wish to use the defaults.
        //
        //   caption:
        //     The text to display in the title bar of the message box.
        //
        //   buttons:
        //     One of the System.Windows.Forms.MessageBoxButtons values that specifies which
        //     buttons to display in the message box.
        //
        //   defaultButton:
        //     One of the System.Windows.Forms.MessageBoxDefaultButton values that specifies
        //     the default button for the message box.
        //
        //   text:
        //     The text to display in the message box.
        //
        // Returns:
        //     One of the System.Windows.Forms.DialogResult values.
        //
        // Exceptions:
        //   System.ComponentModel.InvalidEnumArgumentException:
        //     buttons is not a member of System.Windows.Forms.MessageBoxButtons.-or- icon
        //     is not a member of System.Windows.Forms.MessageBoxIcon.-or- The defaultButton
        //     specified is not a member of System.Windows.Forms.MessageBoxDefaultButton.
        //
        //   System.ArgumentException:
        //     options specified both System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly
        //     and System.Windows.Forms.MessageBoxOptions.ServiceNotification.-or- buttons
        //     specified an invalid combination of System.Windows.Forms.MessageBoxButtons.
        //
        //   System.InvalidOperationException:
        //     An attempt was made to display the System.Windows.Forms.MessageBox in a process
        //     that is not running in User Interactive mode. This is specified by the System.Windows.Forms.SystemInformation.UserInteractive
        //     property.
        public static DialogResult Show(String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options)
        {
            ApplicationAlert al = new ApplicationAlert();
            al.label1.Text = text;
            al.Text = caption;

            al.SetButtons(buttons);
            al.SetIcon(icon);
            al.SetDefaultButton(defaultButton);
            al.SetOptions(options);

            return al.ShowDialog();
        }
        //
        // Summary:
        //     Displays a message box in front of the specified object and with the specified
        //     text, caption, buttons, icon, default button, and options.
        //
        // Parameters:
        //   Text:
        //     The text to display in the message box.
        //
        //   Icon:
        //     One of the System.Windows.Forms.MessageBoxIcon values that specifies which
        //     icon to display in the message box.
        //
        //   Options:
        //     One of the System.Windows.Forms.MessageBoxOptions values that specifies which
        //     display and association options will be used for the message box. You may
        //     pass in 0 if you wish to use the defaults.
        //
        //   Owner:
        //     An implementation of System.Windows.Forms.IWin32Window that will own the
        //     modal dialog box.
        //
        //   Buttons:
        //     One of the System.Windows.Forms.MessageBoxButtons values that specifies which
        //     buttons to display in the message box.
        //
        //   defaultButton:
        //     One of the System.Windows.Forms.MessageBoxDefaultButton values the specifies
        //     the default button for the message box.
        //
        //   Caption:
        //     The text to display in the title bar of the message box.
        //
        // Returns:
        //     One of the System.Windows.Forms.DialogResult values.
        //
        // Exceptions:
        //   System.ArgumentException:
        //     options specified both System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly
        //     and System.Windows.Forms.MessageBoxOptions.ServiceNotification.-or- options
        //     specified System.Windows.Forms.MessageBoxOptions.DefaultDesktopOnly or System.Windows.Forms.MessageBoxOptions.ServiceNotification
        //     and specified a value in the owner parameter. These two options should be
        //     used only if you invoke the version of this method that does not take an
        //     owner parameter.-or- buttons specified an invalid combination of System.Windows.Forms.MessageBoxButtons.
        //
        //   System.ComponentModel.InvalidEnumArgumentException:
        //     buttons is not a member of System.Windows.Forms.MessageBoxButtons.-or- icon
        //     is not a member of System.Windows.Forms.MessageBoxIcon.-or- defaultButton
        //     is not a member of System.Windows.Forms.MessageBoxDefaultButton.
        //
        //   System.InvalidOperationException:
        //     An attempt was made to display the System.Windows.Forms.MessageBox in a process
        //     that is not running in User Interactive mode. This is specified by the System.Windows.Forms.SystemInformation.UserInteractive
        //     property.
        public static DialogResult Show(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options)
        {
            ApplicationAlert al = new ApplicationAlert();
            al.label1.Text = text;
            al.Text = caption;

            al.SetButtons(buttons);
            al.SetIcon(icon);
            al.SetDefaultButton(defaultButton);
            al.SetOptions(options);

            return al.ShowDialog(owner);
        }
    }

    public class CheckBoxParameters
    {
        private bool m_value;

        public bool Value
        {
            get { return m_value; }
            set { m_value = value; }
        }
        private String m_text;


        public String Text
        {
            get { return m_text; }
            set { m_text = value; }
        }
    }
}